﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.CodeDom.Compiler;

namespace CodeEditor
{
    public partial class ErrorWindow : DigitalRune.Windows.Docking.DockableForm
    {
        /// <summary>
        /// Compiler Errors setzen.
        /// </summary>
        public CompilerErrorCollection Errors
        {
            set
            {
                dataGridViewErrorList.Rows.Clear();
                dataGridViewWarningList.Rows.Clear();
                int errorCount = 0, warningCount = 0;
                foreach (CompilerError error in value)
                {

                    Object[] errorInfo = new Object[4];
                    errorInfo[0] = error.ErrorNumber;
                    errorInfo[1] = error.ErrorText;
                    errorInfo[2] = error.FileName;
                    errorInfo[3] = error.Line;

                    if (error.IsWarning)
                    {
                        dataGridViewWarningList.Rows.Add(errorInfo);
                        warningCount++;
                    }
                    else
                    {
                        dataGridViewErrorList.Rows.Add(errorInfo);
                        errorCount++;
                    }
                }
                tabPageErrors.Text = Properties.Resources.ErrorsText + " (" + errorCount.ToString() + ")";
                tabPageWarnings.Text = Properties.Resources.WarningsText + " (" + warningCount.ToString() + ")";
                dataGridViewErrorList.AutoResizeColumns();
                dataGridViewWarningList.AutoResizeColumns();
            }
        }
        
        public ErrorWindow()
        {
            InitializeComponent();
            Errors = new CompilerErrorCollection();
        }
    }
}
